package shili;

import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantLock;

public class reentrantLock {
    private static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();
        //Semaphore semaphore = new Semaphore(1);
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                //semaphore.acquire();
                lock.lock();
                count++;
                lock.unlock();
                //semaphore.release();

            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                lock.lock();

                //semaphore.acquire();
                count++;
                //semaphore.release();
                lock.unlock();

            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(count);
        //输出结果100000
    }
}
